<?php
	class ShangpuAction extends BaseAction{
		public function shangpuadd(){
			if(!$this->isPost()){
				//区域
				$result = M("area")->select();
				$this->assign("area",$result);
				//地铁站
				$ditie  = M("subway")->select();
				$this->assign("ditie",$ditie);
				//租赁方式
				$rent = M("rent")->select();
				$this->assign("rent",$rent);
				//房源类型
				$type = M("type")->select();
				$this->assign("type",$type);
				//商圈
				$district = M("district")->select();
				$this->assign("district",$district);
				//经纪人
				$broker = M("vip")->where("v_type =1 ")->select();
				$this->assign("broker",$broker);
				$this->display();
			}else{
				//获得图片
				$pic = $_FILES['s_img'];
				//获得图的临时路径
				$tmpname = $pic['tmp_name'];
				//获得图片类型
				$type = $pic['type'];
				$type = explode('/',$type);
				$type_1 = $type[0];
				//重新给图片起名
				$picture='shangpu_'.time().rand(1000,9999).".".$type[1];
				//上传图片时 的报错
				$error=$pic['error'];
				//图片上传的路径
				$newname=ROOT_DIR.DS.'Public/Upload/'.$picture;
				if(is_uploaded_file($tmpname) && $type_1 == 'image' && $error == '0'){
					move_uploaded_file($tmpname,$newname);
				}
				
				
				//楼盘名字
				$data['s_name']=$_POST['s_name'];
				//楼盘图片
				$data['s_img'] = $picture;
				//楼盘位置
				$data['s_location']=$_POST['location'];
				//所 属  区
				$data['s_quyu']=$_POST['s_quyu'];
				//所属商圈
				$data['s_district']=$_POST['s_district'];
				//所属地铁线
				$data['s_subway']=$_POST['s_subway'];
				//所属地铁站
				$data['s_subway_station']=$_POST['s_subway_station'];
				//租赁方式
				$data['s_zulin']=$_POST['s_zulin'];
				//房源类型
				$data['s_type']=$_POST['s_type'];
				//房源位置
				$data['s_location']=$_POST['s_location'];
				//开发商
				$data['s_developers']=$_POST['s_developers'];
				//单价
				$data['s_sell']=$_POST['s_sell'];
				//总价
				$data['s_zongjia']=$_POST['s_zongjia'];
				//日租金
				$data['s_d_rent']=$_POST['s_d_rent'];
				//月租金
				$data['s_m_rent']=$_POST['s_m_rent'];
				//建筑面积
				$data['s_build_area']=$_POST['s_build_area'];
				//使用面积
				$data['s_use_area']=$_POST['s_use_area'];
				//详细标题
				$data['s_title']=$_POST['s_title'];
				//所在楼层
				$data['s_floor']=$_POST['s_floor'];
				//装修状况
				$data['s_decoration']=$_POST['s_decoration'];
				//楼盘等级
				$data['s_rating']=$_POST['s_rating'];
				//支付方式
				$data['s_pay_type']=$_POST['s_pay_type'];
				//配套设施
				$data['s_supproting']=$_POST['s_supproting'];
				//房源描述
				$data['s_description_info']=$_POST['s_description_info'];
				//图片描述
				$data['s_description_img']=$_POST['s_description_img'];
				//地图交通
				$data['s_description_map']=$_POST['s_description_map'];
				//楼盘简介
				$data['s_summary_info']=$_POST['s_summary_info'];
				//周边设施
				$data['s_nearby']=$_POST['s_nearby'];
				//所属经纪人
				$data['s_broker'] = $_POST['brokers'];
				
				$result = M("shangpu")->data($data)->add();

				if($result){
					$this->assign("jumpUrl","__URL__/xiezilouadd");
					$this->assign("waitSecond",3);
					$this->success("写字楼添加成功！！！");
				}else{	
					$this->assign("jumpUrl","__URL__/xiezilouadd");
					$this->assign("waitSecond",3);
					$this->error("添加失败！！！");
				}


				//$data['']=$_POST[''];
			}
		}

		public function lists(){
			if(!$this->isPost()){
				$xiezilou = M("shangpu")->select();
				$this->assign("result",$xiezilou);
				$this->display();
			}else{
				if($_POST['fun']=="del"){
					$s_id = $_POST['s_id'];
					$result = M("shangpu")->where("s_id=$s_id")->delete();
					if($result){
						echo "1"; 
					}else{
						echo "0";
					}
				}
				if($_POST['fun']=='updates'){
					$s_id = $_POST['s_id'];
					$result = M("shangpu")->where("s_id=$s_id")->select();

					$this->assign("result",$result);	
				
					//区域
					$result = M("area")->select();
					$this->assign("area",$result);
					//地铁站
					$ditie  = M("subway")->select();
					$this->assign("ditie",$ditie);
					//租赁方式
					$rent = M("rent")->select();
					$this->assign("rent",$rent);
					//房源类型
					$type = M("type")->select();
					$this->assign("type",$type);
					//商圈
					$district = M("district")->select();
					$this->assign("district",$district);
					//经纪人
					$broker = M("vip")->where("v_type =1 ")->select();
					$this->assign("broker",$broker);
					$this->display();
					$this->display("updates");
				}
				if($_POST['fun']=='u'){
					$s_id = $_POST['s_id'];
					//获得图片
					$pic = $_FILES['s_img'];
					//获得图的临时路径
					$tmpname = $pic['tmp_name'];
					//获得图片类型
					$type = $pic['type'];
					$type = explode('/',$type);
					$type_1 = $type[0];
					//重新给图片起名
					$picture='shangpu_'.time().rand(1000,9999).".".$type[1];
					//上传图片时 的报错
					$error=$pic['error'];
					//图片上传的路径
					$newname=ROOT_DIR.DS.'Public/Upload/'.$picture;
					if(is_uploaded_file($tmpname) && $type_1 == 'image' && $error == '0'){
						move_uploaded_file($tmpname,$newname);
					}
					
					
					//楼盘名字
					$data['s_name']=$_POST['s_name'];
					//楼盘图片
					$data['s_img'] = $picture;
					//楼盘位置
					$data['s_location']=$_POST['location'];
					//所 属  区
					$data['s_quyu']=$_POST['s_quyu'];
					//所属商圈
					$data['s_district']=$_POST['s_district'];
					//所属地铁线
					$data['s_subway']=$_POST['s_subway'];
					//所属地铁站
					$data['s_subway_station']=$_POST['s_subway_station'];
					//租赁方式
					$data['s_zulin']=$_POST['s_zulin'];
					//房源类型
					$data['s_type']=$_POST['s_type'];
					//房源位置
					$data['s_location']=$_POST['s_location'];
					//开发商
					$data['s_developers']=$_POST['s_developers'];
					//单价
					$data['s_sell']=$_POST['s_sell'];
					//总价
					$data['s_zongjia']=$_POST['s_zongjia'];
					//日租金
					$data['s_d_rent']=$_POST['s_d_rent'];
					//月租金
					$data['s_m_rent']=$_POST['s_m_rent'];
					//建筑面积
					$data['s_build_area']=$_POST['s_build_area'];
					//使用面积
					$data['s_use_area']=$_POST['s_use_area'];
					//详细标题
					$data['s_title']=$_POST['s_title'];
					//所在楼层
					$data['s_floor']=$_POST['s_floor'];
					//装修状况
					$data['s_decoration']=$_POST['s_decoration'];
					//楼盘等级
					$data['s_rating']=$_POST['s_rating'];
					//支付方式
					$data['s_pay_type']=$_POST['s_pay_type'];
					//配套设施
					$data['s_supproting']=$_POST['s_supproting'];
					//房源描述
					$data['s_description_info']=$_POST['s_description_info'];
					//图片描述
					$data['s_description_img']=$_POST['s_description_img'];
					//地图交通
					$data['s_description_map']=$_POST['s_description_map'];
					//楼盘简介
					$data['s_summary_info']=$_POST['s_summary_info'];
					//周边设施
					$data['s_nearby']=$_POST['s_nearby'];
					//所属经纪人
					$data['s_broker'] = $_POST['brokers'];
					$result = M("xiezilou")->data($data)->where("s_id = $s_id")->save();
					if($result){
						$this->assign("jumpUrl","__URL__/lists");
						$this->assign("waitSecond",3);
						$this->success("修改成功！！！");
					}else{
						$this->assign("jumpUrl","__URL__/lists");
						$this->assign("waitSecond",3);
						$this->error("修改失败！！！");					
					}
				}
			}
		
		}
		

	}